﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
///  Image拓展
/// </summary>
[RequireComponent(typeof(UIType))]
public class UIImageExtension : Image
{
   

#if UNITY_EDITOR
    [MenuItem("GameObject/UI/ImageEx")]
    static void CreateImageEx(MenuCommand menuCmd)
    {
        // 创建游戏对象
        float w = 100f;
        float h = 100f;
        GameObject btnRoot =UICommon.CreateUIElementRoot("ImageEx", w, h);

       

        // 添加脚本
        btnRoot.AddComponent<CanvasRenderer>();
        Image img = btnRoot.AddComponent<UIImageExtension>();
        img.color = Color.white;
        img.fillCenter = true;
        img.raycastTarget = true;
        img.sprite = UICommon.FindRes<Sprite>("UISprite");
        if (img.sprite != null)
            img.type = Image.Type.Sliced;

        //btnRoot.AddComponent<UIButtonExtension>();
        //btnRoot.GetComponent<Selectable>().image = img;

        // 放入到UI Canvas中
        UICommon.PlaceUIElementRoot(btnRoot, menuCmd);
    }
#endif
}
